001 /*
002 * Copyright 2005 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.station.info;
020
021 import java.util.Properties;
022 import java.net.URI;
023
024 import net.dpml.transit.info.CodeBaseDirective;
025
026 import net.dpml.lang.ValueDirective;
027
028 /**
029 * The ApplicationDescriptor is immutable datastructure used to
030 * describe an application.
031 *
032 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
033 * @version 1.0.0
034 */
035 public class ApplicationDescriptor extends CodeBaseDirective
036 {
037 /**
038 * The default startup timeout in seconds.
039 */
040 public static final int DEFAULT_STARTUP_TIMEOUT = 6;
041
042 /**
043 * The default shutdown timeout in seconds.
044 */
045 public static final int DEFAULT_SHUTDOWN_TIMEOUT = 6;
046
047 private final String m_base;
048 private final StartupPolicy m_policy;
049 private final int m_startup;
050 private final int m_shutdown;
051 private final Properties m_properties;
052 private final URI m_config;
053 private final String m_title;
054
055 /**
056 * Creation of a new codebase descriptor.
057 * @param codebase the codebase uri
058 * @param title the profile title
059 * @param parameters an array of plugin parameter descriptors
060 * @param base working directory path
061 * @param policy the application startup policy
062 * @param startupTimeout startup timeout value
063 * @param shutdownTimeout shutdown timeout value
064 * @param properties system properties
065 * @param config uri to a part configuration
066 */
067 public ApplicationDescriptor(
068 URI codebase, String title, ValueDirective[] parameters, String base,
069 StartupPolicy policy, int startupTimeout, int shutdownTimeout,
070 Properties properties, URI config )
071 {
072 super( codebase, parameters );
073
074 if( null == properties )
075 {
076 throw new NullPointerException( "properties" );
077 }
078 if( null == parameters )
079 {
080 throw new NullPointerException( "parameters" );
081 }
082 if( null == title )
083 {
084 throw new NullPointerException( "title" );
085 }
086 if( null == policy )
087 {
088 throw new NullPointerException( "policy" );
089 }
090
091 m_base = base;
092 m_policy = policy;
093 m_startup = startupTimeout;
094 m_shutdown = shutdownTimeout;
095 m_properties = properties;
096 m_title = title;
097 m_config = config;
098 }
099
100 /**
101 * Returns the application title.
102 *
103 * @return the title
104 */
105 public String getTitle()
106 {
107 return m_title;
108 }
109
110 /**
111 * Returns the path defining the basedir that the application will be deployed within.
112 *
113 * @return the bassedir path
114 */
115 public String getBasePath()
116 {
117 return m_base;
118 }
119
120 /**
121 * Return the application startup policy.
122 *
123 * @return the startup policy
124 */
125 public StartupPolicy getStartupPolicy()
126 {
127 return m_policy;
128 }
129
130 /**
131 * Get the duration in seconds to wait for startup
132 * of the application before considering deployment as a timeout failure.
133 *
134 * @return the startup timeout value
135 */
136 public int getStartupTimeout()
137 {
138 return m_startup;
139 }
140
141 /**
142 * Get the duration in seconds to wait for the shutdown
143 * of the application before considering the process as non-responsive.
144 *
145 * @return the shutdown timeout value
146 */
147 public int getShutdownTimeout()
148 {
149 return m_shutdown;
150 }
151
152 /**
153 * Get the system properties.
154 *
155 * @return the system properties
156 */
157 public Properties getSystemProperties()
158 {
159 return m_properties;
160 }
161
162 /**
163 * Get the configuration uri specification.
164 *
165 * @return the configuration uri spec
166 */
167 public String getConfigurationURISpec()
168 {
169 if( null == m_config )
170 {
171 return null;
172 }
173 else
174 {
175 return m_config.toASCIIString();
176 }
177 }
178
179 /**
180 * Get the configuration uri.
181 *
182 * @return the configuration uri
183 */
184 public URI getConfigurationURI()
185 {
186 return m_config;
187 }
188
189 /**
190 * Compare this object with another for equality.
191 * @param other the object to compare this object with
192 * @return TRUE if the supplied object equivalent
193 */
194 public boolean equals( Object other )
195 {
196 if( !super.equals( other ) )
197 {
198 return false;
199 }
200 else if( !( other instanceof ApplicationDescriptor ) )
201 {
202 return false;
203 }
204 else
205 {
206 ApplicationDescriptor descriptor = (ApplicationDescriptor) other;
207 if( !equals( m_base, descriptor.m_base ) )
208 {
209 return false;
210 }
211 else if( !equals( m_policy, descriptor.m_policy ) )
212 {
213 return false;
214 }
215 else if( m_startup != descriptor.m_startup )
216 {
217 return false;
218 }
219 else if( m_shutdown != descriptor.m_shutdown )
220 {
221 return false;
222 }
223 else if( !equals( m_properties, descriptor.m_properties ) )
224 {
225 return false;
226 }
227 else if( !equals( m_config, descriptor.m_config ) )
228 {
229 return false;
230 }
231 else
232 {
233 return equals( m_title, descriptor.m_title );
234 }
235 }
236 }
237
238 /**
239 * Return the hashcode for the object.
240 * @return the hashcode value
241 */
242 public int hashCode()
243 {
244 int hash = super.hashCode();
245 hash ^= hashValue( m_base );
246 hash ^= hashValue( m_policy );
247 hash ^= m_startup;
248 hash ^= m_shutdown;
249 hash ^= hashValue( m_properties );
250 hash ^= hashValue( m_config );
251 hash ^= hashValue( m_title );
252 return hash;
253 }
254
255 /**
256 * Return a string representation of the application descriptor.
257 * @return the string value
258 */
259 public String toString()
260 {
261 StringBuffer buffer = new StringBuffer( "[application uri=" );
262 buffer.append( getCodeBaseURISpec() );
263 buffer.append( " policy=" + m_policy );
264 buffer.append( " ]" );
265 return buffer.toString();
266 }
267 }